using UnityEngine;
using System.Collections;

public class Winner : MonoBehaviour {
	
	// X + Left; Y + Frount;  Z + down;  <-rotation caused
	public GameObject youPrefab;	
	private GameObject youControl;
	
	public GameObject typePrefab;	
	private GameObject typeControl;
	
	public GameObject extremePrefab;	
	private GameObject extremeControl;
	
	public GameObject fastPrefab;	
	private GameObject fastControl;
	
	
	
	
	int clock = 0;
	
	
	// Use this for initialization
	void Start () {
		youControl = (GameObject) Instantiate(youPrefab,new Vector3(-4.3f, 15.3f, -1), Quaternion.identity);
		youControl.transform.Rotate( 90f, 180f, 0f);
		typeControl = (GameObject) Instantiate(typePrefab,new Vector3(-21, -0.5f, -1), Quaternion.identity);
		typeControl.transform.Rotate( 90f, 180f, 0f);
		extremeControl = (GameObject) Instantiate(extremePrefab,new Vector3(1, -9, -1), Quaternion.identity);
		extremeControl.transform.Rotate( 90f, 180f, 0f);
		fastControl = (GameObject) Instantiate(fastPrefab,new Vector3(27.5f, 1.5f, -1), Quaternion.identity);
		fastControl.transform.Rotate( 90f, 180f, 0f);
	}
	
	// Update is called once per frame
	void Update () {
		clock ++;
		if (clock < 60){  // -6 2 -1
			youControl.transform.Translate( 0, 0, 0.21f);
		}else if (clock > 59 && clock < 120){
			youControl.transform.Rotate( 0f, 6f, 0f);  //spin			
		}else if (clock > 119 && clock < 180){     // -4.3 3.3  -1
			typeControl.transform.Translate( -0.333333f, 0, 0);
		}else if (clock > 179 && clock < 210){  //lengthen
			typeControl.transform.localScale += new Vector3(0.05f,0,0);
		}else if (clock > 209 && clock < 240){
			typeControl.transform.localScale -= new Vector3(0.05f,0,0);
		}else if (clock > 239 && clock < 300){		//  1  -2.5  -1
			extremeControl.transform.Translate( 0, 0, -0.10833333f);
		}else if (clock > 299 && clock < 329){
			extremeControl.transform.Translate( 0, 0.1f, -0.02f); //jump to the screen
		}else if (clock > 330 && clock < 360){
			extremeControl.transform.Translate( 0, -0.1f, 0.02f);
		}else if (clock > 359 && clock < 420){  		// -2.5 1.5 -1
			fastControl.transform.Translate( 0.5f, 0, 0);
		}else if (clock > 419 && clock < 480){		//harlem shake
			if (clock % 8 == 0 ){
				fastControl.transform.Translate( 0.04f, 0, 0);
				fastControl.transform.Rotate( 0, 4, 0);
			}else if (clock % 8 == 1){
				fastControl.transform.Translate( -0.02f, 0, 0);
				fastControl.transform.Rotate( 0, -2, 0);
			}else if (clock % 8 == 2){
				fastControl.transform.Translate( 0.02f, 0, 0);
				fastControl.transform.Rotate( 0, 2, 0);
			}else if (clock % 8 == 3){
				fastControl.transform.Translate( -0.04f, 0, 0);
				fastControl.transform.Rotate( 0, -4, 0);
			}else if (clock % 8 == 4){
				fastControl.transform.Translate( -0.04f, 0, 0);
				fastControl.transform.Rotate( 0, -4, 0);
			}else if (clock % 8 == 5){
				fastControl.transform.Translate( 0.02f, 0, 0);
				fastControl.transform.Rotate( 0, 2, 0);
			}else if (clock % 8 == 6){
				fastControl.transform.Translate( -0.02f, 0, 0);
				fastControl.transform.Rotate( 0, -2, 0);
			}else if (clock % 8 == 7){
				fastControl.transform.Translate( 0.04f, 0, 0);
				fastControl.transform.Rotate( 0, 4, 0);
			}
			
			
		}else if (clock > 600){
			Application.LoadLevel("Menu");
			
		}
	}
}
